package com.example.musicplayer.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 把加密对象存入bean中
 * config 是用于存放bean的目录
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Bean
    public BCryptPasswordEncoder getBCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        LoginInterceptor loginInterceptor = new LoginInterceptor();
        registry.addInterceptor(loginInterceptor)
                        .addPathPatterns("/**")
                        //排除所有的JS
                        .excludePathPatterns("/js/**.js")
                        //排除images下所有的元素
                        .excludePathPatterns("/images/**")
                        .excludePathPatterns("/css/**.css")
                        .excludePathPatterns("/fronts/**")
                        .excludePathPatterns("/player/**")
                        .excludePathPatterns("/login.html")
                        .excludePathPatterns("/register.html")
                        //排除登录和注册接口
                        .excludePathPatterns("/user/login")
                        .excludePathPatterns("/user/register");

    }
}
